<?
/*
 *  GGB - Gelin's Guest Book.
 *  Copyright (C) 2006  Denis Nelubin aka Gelin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  http://gelin.ru
 *  mailto:den@gelin.ru
 *
 *  Description:    Main page, dispatcher.
 *
 *  History:
 *  2006-06-25  Gelin   Initially created.
 *  2007-02-04  Gelin   Changed check for ban.
 *
 */

header('Content-type: text/html; charset=UTF-8');

session_start();
require_once('lib/functions.php');

//define profile
$profile = getParameter('profile');
if (!isset($profile) || !is_readable("profile/$profile.php")) {
    $profile = 'default';
}
$_SESSION['profile'] = $profile;
require_once("profile/$profile.php");

require_once($config['require']['storage']);
require_once($config['require']['formatter']);
require_once($config['require']['ban_checker']);
require_once($config['require']['logger']);

//create logger
$log = new Logger();
$log->restore();

//create storage
$storage = new Storage();

//create formatter
$format = new Formatter();

//create ban checker
$banChecker = new BanChecker();

//dispatch by action
$action = getParameter('action');

if ($action != '') {    //not default action
    //check for access
    $headers = $banChecker->getRequestHeaders();
    if (!$banChecker->checkForBan($headers)) {  //access is denied
        $log->error($lang['error.access.denied']);
    }
}

if (!$log->isErrorsEmpty()) { //have error
    $action = '';   //only default (view) action is allowed
}

switch ($action) {
case 'add':
    require_once('action/add.php'); //add message form
    break;
case 'add-submit':
    require_once('action/add-submit.php');  //submits new added message
    break;
default:
    require_once('action/view.php');
}

?>